import axios from 'axios';

window.ajax = {};
(function(){
    let ES = 'develop';
    let base = '';

    this.api = function(url){
        if(process.env.NODE_ENV === 'production'){
            base = "//www.baidu.com";
        }else if(process.env.NODE_ENV === 'development'){
            base = "//me.api.com";
        }
        return base + url;
    };

    this.request = function(option){
        const req = axios.create({
            method:option.type,
            url:this.api(option.url),
            headers: {'Authorization': '445'},
            data:option.data,
            //baseURL: this.$getUrl('')
        });
        req()
            .then(function (response) {
                option.success && option.success(response.data)
            })
            .catch(function(error) {
                console.log(error)
            });
    }

}).apply(ajax);
